package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.hzphfin.HzphfinFraudScoreT3Record;
import com.ucredit.babel.common.model.hzphfin.HzphfinScoreData;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 恒普数科反欺诈评分
 * @author szw
 *
 */
public class HzphfinFraudScoreT3RecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     *
     * 恒普数科反欺诈评分
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        HzphfinFraudScoreT3Record obj= (HzphfinFraudScoreT3Record)model;
        HzphfinScoreData data = obj.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        StringBuilder hsSb = new StringBuilder(2000);

        //返回状态码 error_code
        hsSb.append(data.getErrorCode()).append(CRT001);
        //返回状态码信息 error_msg
        hsSb.append(data.getErrorMsg()).append(CRT001);
        //返回结果 data
        hsSb.append(data.getData()).append(CRT001);
        //流水号 seqNo
        hsSb.append(data.getSeqNo()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + hsSb.toString() + txSb.toString()).replace("\n","").replace("\r", " "));
        context.write(key,val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_hzphfin_fraud_score_t3_inc";
    }

    @Override
    public String getType() {
        return RecordType.HZPHFIN_FRAUD_SCORE_T3_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "恒普数科反欺诈评分";
    }
}
